package com.dsp.soundscape.model;

import java.io.Serializable;
import java.util.List;

import com.dsp.soundscape.util.RestUtil;


public class AlbumInfo implements Comparable <AlbumInfo>, Serializable {
	private static final long serialVersionUID = -7118183351912861549L;
	
	private String artist;
	private String album;
	private String year;
	private String fullpath;
	private String path;
	private String image;
	private String imagepath;
	private String thumbpath;
	
	private boolean imageAvailable = false;

	private List<SongInfo> songs;
	
	private boolean populated = false;
	
	public String getImagepath() {
		return imagepath;
	}
	public void setImagepath(String imagepath) {
		this.imagepath = imagepath;
		imageAvailable = true;
	}
	
	public String getThumb() {
		return thumbpath;
	}
	public void setThumb(String thumbpath) {
		this.thumbpath = thumbpath;
	}
	
	public boolean isImageAvailable() {
		return imageAvailable;
	}
	
	public void setArtist(String artist) {
		this.artist = artist;
	}
	public void setAlbum(String album) {
		this.album = album;
	}
	public void setYear(String year) {
		this.year = year;
	}
	public void setPopulated(boolean populated) {
		this.populated = populated;
	}
	
	public String getImage() {
		return image;
	}
	public void setImage(String image) {
		this.image = image;
	}

	public List<SongInfo> getSongs() {
		return songs;
	}
	public void setSongs(List<SongInfo> songs) {
		this.songs = songs;
	}

	public void setFullpath(String fullpath) {
		this.path = fullpath.substring(fullpath.lastIndexOf("/") + 1);
		this.fullpath = fullpath;
		
		String[] pieces = path.split("[ ]-[ ]");
		if (pieces.length == 3) {
			artist = pieces[0];
			year = pieces[1];
			album = pieces[2];
		}
	}
	
	public String getFullpath() {
		return fullpath;
	}

	public String getPath() {
		return path;
	}
	
	public String getArtist() {
		return artist;
	}

	public String getAlbum() {
		return album;
	}

	public String getYear() {
		return year;
	}

	public boolean isPopulated() {
		return populated;
	}

	public int compareTo(AlbumInfo obj) {
		return (artist + " " + year + " " + album).toLowerCase()
			.compareTo((obj.getArtist() + " " + obj.getYear() + " " + obj.getAlbum()).toLowerCase());
	}
	
	public String getArtistRest() {
		return RestUtil.convert(artist);
	}
	
	public String getAlbumRest() {
		return RestUtil.convert(album);
	}
	
	public String getId() {
		return getArtistRest() + "/" + getYear() + "/" + getAlbumRest();
	}
	
	@Override
	public String toString() {
		return "AlbumInfo [album=" + album + ", albumRest=" + getAlbumRest() + ", artist=" + artist
				+ ", artistRest=" + getArtistRest() + ", fullpath=" + fullpath + ", image=" + image
				+ ", imageAvailable=" + imageAvailable + ", imagepath="
				+ imagepath + ", path=" + path + ", populated=" + populated
				+ ", songs=" + songs + ", year=" + year + "]";
	}
	
}